package com.heima.article.controller.v1;

import com.heima.article.constant.Constant;
import com.heima.article.service.ArticleService;
import com.heima.model.article.dto.ArticleHomeDto;
import com.heima.model.article.pojo.ApArticle;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 文章首页控制器
 *
 * @Author ilurfucy
 * @Date 2022/8/28     9:59
 * @Description 文章首页控制器
 **/
@RestController
@RequestMapping("/api/v1/article")
public class ArticleHomeController {

    @Autowired
    ArticleService articleService;


    /**
     * 首页加载
     *
     * @param dto
     * @return
     */
    @PostMapping("/load")
    public ResponseResult load(@RequestBody ArticleHomeDto dto) {
        List<ApArticle> articleList = articleService.getArticleListByLoadType(Constant.LOAD_ARTICLE_TYPE_DEFAULT, dto);
        return ResponseResult.okResult(articleList);
    }

    /**
     * 加载更多
     *
     * @param dto
     * @return
     */
    @PostMapping("/loadmore")
    public ResponseResult loadMore(@RequestBody ArticleHomeDto dto) {
        List<ApArticle> articleList = articleService.getArticleListByLoadType(Constant.LOAD_ARTICLE_TYPE_MORE, dto);
        return ResponseResult.okResult(articleList);
    }

    /**
     * 加载最新
     *
     * @param dto
     * @return
     */
    @PostMapping("/loadnew")
    public ResponseResult loadNew(@RequestBody ArticleHomeDto dto) {
        List<ApArticle> articleList = articleService.getArticleListByLoadType(Constant.LOAD_ARTICLE_TYPE_NEW, dto);
        return ResponseResult.okResult(articleList);
    }

    ;
}